﻿using System.Threading;
using System.Threading.Tasks;
using System.Windows;

namespace Xcj.Mes.Core.CustomControls
{
    public class ReportBox
    {
        public static void Show(string msg, string caption = "提示", 
            MessageBoxButton buttons = MessageBoxButton.OK, MessageBoxImage icon = MessageBoxImage.Error)
        {
            ShowMessageBoxParameter param = new ShowMessageBoxParameter
            {
                msg     = msg,
                buttons = buttons,
                caption = caption,
                icon    = icon
            };

            new Task((p) =>
            {
                Thread.CurrentThread.IsBackground = true;
                Thread.CurrentThread.Priority     = ThreadPriority.Lowest;
                ShowMessageBoxParameter _param    = (ShowMessageBoxParameter)p;
                MessageBox.Show(_param.msg, _param.caption, _param.buttons, _param.icon, _param.result, _param.options);
            }, param).Start();
        }

        public static MessageBoxResult ShowDialog(string msg, string caption = "提示", 
            MessageBoxButton buttons = MessageBoxButton.OK, MessageBoxImage icon = MessageBoxImage.Error)
        {
            ShowMessageBoxParameter param = new ShowMessageBoxParameter
            {
                msg     = msg,
                buttons = buttons,
                caption = caption,
                icon    = icon
            };

            return MessageBox.Show(param.msg, param.caption, param.buttons, param.icon, param.result, param.options);
        }

        private class ShowMessageBoxParameter
        {
            public string msg                = string.Empty;
            public string caption            = "提示";
            public MessageBoxButton buttons  = MessageBoxButton.OK;
            public MessageBoxImage icon      = MessageBoxImage.Information;
            public MessageBoxResult result   = MessageBoxResult.Cancel;
            public MessageBoxOptions options = MessageBoxOptions.ServiceNotification;
        }
    }
}
